<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://www.skysz.com/framework" prefix="skysz"%>

<s:i18n name="com/skysz/framework/package">
	<table width="100%" height="100%">
		<tr>
			<td style="padding: 3px;" valign="top">
				<table width="100%" height="100%">
					<tr>
						<td class="layout_win_bar_query">
							<div style="float: left">开单信息</div>
							<div id="mr.pay.paymain.open.handler"
								style="background-image: url('../resource/images/div_block.gif')"
								class="div_tool_right"
								onclick="skysz.utils.divOpenOrClose('mr.pay.paymain.open.handler','mr.pay.paymain.open.form')"
								class="div_open"></div></td>
					</tr>
					<tr>
						<td class="tb_searchbar_container">
							<table class="tb_searchbar" id='mr.pay.paymain.open.form'
								cellspacing=1 cellpadding="4">
								<tr>
									<td class="td_title" width="10%">
										项目(快捷键)
									</td>
									<td class="td_field" >
										<skysz:gridInput
											imgId="mr.pay.paymain.open.gridSelector"
											id="mr.pay.paymain.open.form.qcode" /> 
										<input id="mr.pay.paymain.open.form.itemId" type="hidden" />
										<input id="mr.pay.paymain.open.form.itemName" type="hidden" />
										<input id="mr.pay.paymain.open.form.price" type="hidden" />
										<skysz:gridselector
											id="mr.pay.paymain.open.gridSelector"
											idCol="itemId"
											quickQuery="mr.pay.paymain.open.form.qcode"
											sqlkey="mr.pay.itemQuery" title="营业项目"
											queryCols="qcode,itemName" queryTexts="快捷码,名称"
											hiddenCols="itemId"
											showCols="itemName,price,qcode,typeName,rootTypeName"
											showHeader="名称,原价,快捷码,归属类,服务/产品"
											showColsType="ro,ro,ro,ro,ro"
											showColsWidth="150,110,100,110,110"
											targetCols="qcode,itemId,itemName,price"
											targetIds="mr.pay.paymain.open.form.qcode,mr.pay.paymain.open.form.itemId,mr.pay.paymain.open.form.itemName,mr.pay.paymain.open.form.price"
											param="~mr.pay.paymain.open.itemCust()" />
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td class="layout_split_x"></td>
					</tr>
					<tr>
						<td class="layout_win_title">
							<div style="float: left">
								<s:text name='fw.list' />
							</div>
						</td>
					</tr>
					
					<tr style="height: 180px;">
						<td class="layout_win_grid_no_page">
							<table width="100%" height="100%">
								<tr>
									<td>
										<div id="mr.pay.paymain.open.gridbox" class="div_gridbox"></div>
									</td>
								</tr>
								<tr style="display: none;">
									<td id="mr.pay.paymain.open.pagingArea"
										class="layout_win_bar_page"></td>
								</tr>
							</table>
						</td>
					</tr>

					<tr>
						<td class="layout_split_x"></td>
					</tr>
					<tr>
						<td class="layout_win_bar_query">
							<div style="float: left">单据信息</div>
							<div id="mr.pay.paymain.open.handler1"
								style="background-image: url('../resource/images/div_block.gif')"
								class="div_tool_right"
								onclick="skysz.utils.divOpenOrClose('mr.pay.paymain.open.handler1','mr.pay.paymain.open.form1')"
								class="div_open"></div></td>
					</tr>
					<tr>
						<td class="tb_searchbar_container">
							<table class="tb_searchbar" cellspacing=1 cellpadding="4"
								id='mr.pay.paymain.open.form1'>
								<tr>
									<td class="td_title" width="10%">储值卡</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.1" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
								<tr>
									<td class="td_title" width="10%">现金</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.2" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
								<tr>
									<td class="td_title" width="10%">项目卡</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.3" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
								<tr>
									<td class="td_title" width="10%">银行卡</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.4" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
								<tr>
									<td class="td_title" width="10%">免单</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.5" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
								<tr>
									<td class="td_title" width="10%">票卷</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.6" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
								<tr>
									<td class="td_title" width="10%">欠款</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.7" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
								<tr>
									<td class="td_title" width="10%">找零</td>
									<td class="td_field" ><input
										id="mr.pay.paymain.open.form.8" readonly="readonly"
										class="input_text" />
									</td>
								</tr>
							</table>
						</td>
					</tr>

					<tr>
						<td class="layout_split_x"></td>
					</tr>
					<tr>
						<td align="right" valign="bottom" style="margin-top: 1px;">
							<input class="button" type="button" value='结账'
								onclick='alert("结账了");'> 
							<input class="button" type="button" value='保存单'
								onclick='alert("存单了");'> 
							<input class="button" type="button" value='关闭'
								onclick='mr.pay.paymain.open.form.close();'>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>

<c:url var="findAll" value="/mr/pay/payAction.action">
	<c:param name="method" value="findAll"></c:param>
</c:url>	
<c:url var="findCardList" value="/mr/pay/payAction.action">
	<c:param name="method" value="findCardList"></c:param>
</c:url>
<c:url var="loadCustByPhone" value="/mr/pay/payAction.action">
	<c:param name="method" value="loadCustByPhone"></c:param>
</c:url>
<c:url var="findAttachHeaders" value="/mr/pay/payAction.action">
	<c:param name="method" value="findAttachHeaders"></c:param>
</c:url>
	
<script type="text/javascript">				
skysz.namespace("mr.pay.paymain.open");
skysz.onReady(function(){
	var phone = '${param.phone}';
	var  form = new skysz.form('mr.pay.paymain.open.form');
	mr.pay.paymain.open.form = form;
	
	var grid = new dhtmlXGridObject('mr.pay.paymain.open.gridbox');
	grid.setImagePath("../dhtmlx/dhtmlxGrid/imgs/");
	grid.setSkyHeaderAttach(",,,,{E},{E},{E},,");
	grid.setSkyHeader("序号,,项目,原价,折扣,现价,数量,合计,员工业绩");
	grid.setInitWidths("0,40,110,50,50,50,50,100,150");
	grid.setColAlign("center,center,center,right,right,right,right,right,left");
	grid.setColTypes("ro,ro,ro,rmb,skyRo,rmbEd,ed,rmb,ro");
	grid.setColSorting("na,na,na,na,na,na,na,na,na");
 	grid.skyinit(); 
	grid.enablePaging("mr.pay.paymain.open.pagingArea","mr.pay.paymain.open.grid");

	if( phone ) {
		addAttachHeaders();
	}
	grid.loadEmpty();
	
	//新增附加列（主要是会员卡）
	function addAttachHeaders() {
		var actionResponse = skysz.ajax.postSync("${findAttachHeaders}", "phone="+phone);	
 	 	var headers = actionResponse.object;
 	 	if(headers.length > 0 ) {
 	 	 	grid.clearAll(true);
 	 	 	var size = headers.length;
 	 	 	var headerAttach = ",,,,{E},{E},{E},,";
			var gridHeader = "序号,,项目,原价,折扣,现价,数量,合计,员工业绩";
 			var width ="0,40,110,50,50,50,50,100,*";
 			var align = "center,center,center,right,right,right,right,right,left";
 			var type = "ro,ro,ro,rmb,skyEd,rmbEd,skyEd,rmb,ro";
 			var sort ="na,na,na,na,na,na,na,na,na";
 			var idRow = ",,,,,,,";
 			for(var i = 0; i<size; i++ ) {
 				gridHeader += "," + headers[i][1];
 				headerAttach += ",{E}"
 				width += ",80";
 				align += ",right";
 				type += ",rmbEd";
 				sort += ",na";
 				idRow += "," + headers[i][0];
 			}
 			grid.setSkyHeaderAttach(headerAttach);
 			grid.setSkyHeader(gridHeader);
 			grid.setInitWidths(width);
 			grid.setColAlign(align);
 			grid.setColSorting(sort);
 			grid.setColTypes(type);
 			grid.skyinit(); 
 			grid.addRowByIndex("idRow",idRow);
 			//grid.setRowHidden("idRow",true);
 			//grid.enablePaging("cfb.query.suborgbudgetquery.pagingArea","cfb.query.suborgbudgetquery.grid");
 			return true;
 	 	} else {
 	 	 	return false;
 	 	}
	}
	
	//动态组合项目查询条件
	mr.pay.paymain.open.itemCust = function() {
		var s='i.enable_=1';
		var ids = grid.getAllRowIds();
		if( ids.split(",").length > 1 ) {
			ids = ids.substring(ids.indexOf(",")+1);
			s = s + ";idNotIn="+ids;
		}
		return  s;
	};
	
	//快捷码变更
	function qcodeChange() {
		var itemId = skysz.$("mr.pay.paymain.open.form.itemId").value;
		if( itemId ) {
			var itemName = skysz.$("mr.pay.paymain.open.form.itemName").value;
			var price = skysz.$("mr.pay.paymain.open.form.price").value;
			var itemId = skysz.$("mr.pay.paymain.open.form.itemId").value;
			var rowContent = "删,"+itemName + "," + price + ",100%,"+price+",1,"+price+","
			grid.addRowByIndex(itemId,rowContent);
		} 
	}
	//监听快捷码变更
	var lis = new skysz.utils.ValueListener("mr.pay.paymain.open.form.itemId",qcodeChange);
	//关闭页面
	mr.pay.paymain.open.form.close = function () {
		var win = '${param.win}';
		eval(win+".close()");
	};
	
	function init() {
		mr.pay.paymain.open.grid = grid;
	}
	init();
 	 
});
	
</script>
</s:i18n>
